package org.itsky.study.test3;

import java.sql.SQLOutput;
import java.util.Arrays;
import java.util.List;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @Author sky
 * @Site cmtianxie163.com 2020/4/13 10:24
 */
public class StreamAPITest1 {
    public static void main(String[] args) {
        List<String> list = Arrays.asList("java","python","go");

        Stream<String> stream = list.stream();
        Stream<String> parallelStream = list.parallelStream();

        stream.forEach(s -> System.out.println(s));
        System.out.println("----------------------");
        parallelStream.forEach(s -> System.out.println(s));
        System.out.println("----------------------");

        int[] array1 = new int[]{1,2,3,4,5};
        IntStream intStream = Arrays.stream(array1);

        double[] array2 = new double[]{11,22,33,44};
        DoubleStream doubleStream = Arrays.stream(array2);

        intStream.forEach(s -> System.out.println(s));
        doubleStream.forEach(s -> System.out.println(s));
        System.out.println("----------------------");
        Stream<Object> objectStream = Stream.of("1", 1, 1.0, intStream);
        objectStream.forEach(s -> System.out.println(s));
        System.out.println("----------------------");

        //创建无限流
        //遍历前十个偶数
        Stream<Integer> iterateStream = Stream.iterate(10, t -> t + 2).limit(10);
        iterateStream.forEach(s -> System.out.println(s));

        //生成
        //生成十个随机数
        Stream<Double> generateStream = Stream.generate(Math::random).limit(10);
        generateStream.forEach(System.out::println);


    }
}
